Repository Public
1import { getAssetRow, readAsset } from "@/server/assets";2import { sheetFromPreviewToken } from "@/server/misc";34export const dynamic = "force-dynamic";5/** Images of the draft being previewed — and only those — for the holder of a valid preview link. */6export async function GET(_req: Request, ctx: { params: Promise<{ token: string; id: string }> }) {7 const { token, id } = await ctx.params;8 const s = await sheetFromPreviewToken(token);9 if (!s || !s.doc.assets.some((a) => a.assetId === id && a.kind === "image")) return new Response("Not found", { status: 404 });10 const a = await getAssetRow(id);11 if (!a || (a.kind !== "image" && a.kind !== "svg")) return new Response("Not found", { status: 404 });12 return new Response(new Uint8Array(await readAsset(a)), { headers: { "Content-Type": a.mime, "Cache-Control": "private, no-store", "X-Content-Type-Options": "nosniff", "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'; sandbox" } });13}14